﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace Soapi.Contrib.ValueConverters
{
    public class ReputationConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if(value==null)
            {
                return "0";
            }
			
            var rep = System.Convert.ToDouble(value);
                        
            if (rep < 10000)
            {
                return rep.ToString("N0");
            }

            return (rep / 1000).ToString(rep % 1000 == 0 ? "" : "F1") + 'k';
        }



        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}